home *** CD-ROM | disk | FTP | other *** search
- public class CircularStringBuffer {
- private int insertionIndex;
- private int size;
- private int bufferSize;
- private char[] contents;
-
- public CircularStringBuffer(int var1) {
- if (var1 < 0) {
- throw new IllegalArgumentException("bufferSize < 0");
- } else {
- this.bufferSize = var1;
- this.contents = new char[var1];
- this.size = 0;
- this.insertionIndex = 0;
- }
- }
-
- public void append(char var1) {
- if (this.bufferSize != 0) {
- this.contents[this.insertionIndex] = var1;
- if (this.size < this.bufferSize) {
- ++this.size;
- }
-
- ++this.insertionIndex;
- this.insertionIndex %= this.bufferSize;
- }
-
- }
-
- public int getSize() {
- return this.size;
- }
-
- public int getBufferSize() {
- return this.bufferSize;
- }
-
- public String toString() {
- if (this.bufferSize != 0) {
- if (this.size >= this.bufferSize && this.insertionIndex != 0) {
- StringBuffer var1 = new StringBuffer(this.bufferSize);
- var1.append(this.contents, this.insertionIndex, this.bufferSize - this.insertionIndex);
- var1.append(this.contents, 0, this.insertionIndex);
- return var1.toString();
- } else {
- return new String(this.contents, 0, this.size);
- }
- } else {
- return "";
- }
- }
- }
-